package com.woniuxy.comsumer.configuration;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RpcConfiguration {
    //
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        //设置ribbon策略，超时时间，
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        //读取数据的超时时间
        factory.setReadTimeout(10000);
        //连接超时,连接被调用方
        factory.setConnectTimeout(20000);
        return new RestTemplate(factory);
    }
    //设置负载均衡策略，全局设置
    /*@Bean
    public IRule iRule(){
        return new RoundRobinRule();
    }*/
}
